package com.atxiaodei.pagehelp.mybatispagehelper.controller;

import com.atxiaodei.pagehelp.mybatispagehelper.core.TableDataInfo;
import com.atxiaodei.pagehelp.mybatispagehelper.pojo.User;
import com.atxiaodei.pagehelp.mybatispagehelper.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wangmeng
 * @date 2020/9/22
 **/
@RestController
@Slf4j
@RequestMapping(value = "/api")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/user", method = RequestMethod.POST)
    public boolean insert(@RequestBody User user) {
        System.out.println("开始新增...");
        return userService.insert(user);
    }

    @RequestMapping(value = "/user", method = RequestMethod.PUT)
    public boolean update(@RequestBody User user) {
        System.out.println("开始更新...");
        return userService.update(user);
    }

    @RequestMapping(value = "/user", method = RequestMethod.DELETE)
    public boolean delete(@RequestBody User user)  {
        System.out.println("开始删除...");
        return userService.delete(user);
    }

    @RequestMapping(value = "/user", method = RequestMethod.GET)
    public TableDataInfo findByUser(User user) {
        System.out.println("开始查询...");
        return userService.findByListEntity(user);
    }
}
